package controllers

import (
	"github.com/gin-gonic/gin"
	medicaldeptsubDao "jjqzplucky.site/sz-core/internal/dao/medical_dept_sub"
	medicalDeptSubModel "jjqzplucky.site/sz-core/internal/models/medical_dept_sub"
	"jjqzplucky.site/sz-core/pkg/constants"
	"jjqzplucky.site/sz-core/pkg/errors"
)

type MedicalDeptSubController struct{}

func (m *MedicalDeptSubController) GetAll(c *gin.Context) {
	c.Set(constants.ResultData, medicaldeptsubDao.SelectAll())
}

func (m *MedicalDeptSubController) Create(c *gin.Context) {
	model := medicalDeptSubModel.MedicalDeptSub{}
	if err := c.ShouldBindJSON(&model); err != nil {
		c.Error(err)
		return
	}
	if err := medicaldeptsubDao.Create(model); err != nil {
		c.Error(err)
		return
	}
	c.Set(constants.ResultData, nil)
}

func (m *MedicalDeptSubController) Update(c *gin.Context) {
	model := medicalDeptSubModel.MedicalDeptSub{}
	_ = c.ShouldBindJSON(&model)
	if model.Id == 0 {
		c.Error(errors.VALID_ERROR)
		return
	}
	if err := medicaldeptsubDao.Update(model); err != nil {
		c.Error(err)
		return
	}
	c.Set(constants.ResultData, nil)
}